// mypage/accPaypassword/accPaypassword.js
var app=getApp();
var util=require("../../utils/util");

Page({
  /*页面的初始数据*/
  data: {
    type: '',
    old_password: '',
    new_password: '',
    again_password: '',
    show_btn: false
  },
  /*生命周期函数--监听页面加载*/
  onLoad: function (options) {
    var that = this;
    var type=options.type;
    if(options.type==1){
      wx.setNavigationBarTitle({title: '支付密码'})
    }else if(options.type==2){
      wx.setNavigationBarTitle({title: '修改支付密码'})
    }else if(options.type==3){
      wx.setNavigationBarTitle({title: '忘记支付密码'})
    }
    that.setData({type: type})
  },
  inpue_old_passWord:function(e){
    this.setData({old_password: e.detail.value})
    this.lite_btn()
  },
  inpue_new_passWord:function(e){
    this.setData({new_password: e.detail.value})
    this.lite_btn()
  },
  inpue_again_passWord:function(e){
    this.setData({again_password: e.detail.value})
    this.lite_btn()
  },
  lite_btn:function(){
    var that = this,type=that.data.type,old_password=that.data.old_password,new_password=that.data.new_password,again_password=that.data.again_password;
    if(type==2){
      if(old_password&&new_password&&again_password){
        that.setData({show_btn: true})
      }else{
        that.setData({show_btn: false})
      }
    }else{
      if(new_password&&again_password){
        that.setData({show_btn: true})
      }else{
        that.setData({show_btn: false})
      }
    }
  },
  confirm_password:function(){
    var that=this,old_password=that.data.old_password,new_password=that.data.new_password,again_password=that.data.again_password;
    if(old_password.length != 6){
      util.page_show_toast('原密码输入错误',1500)
      return false;
    }
    if(new_password.length != 6){
      util.page_show_toast('新密码输入错误',1500)
      return false;
    }
    if(again_password.length != 6){
      util.page_show_toast('确认密码输入错误',1500)
      return false;
    }
    if(new_password != again_password){
      util.page_show_toast('两次密码输入不一致',1500)
      return false;
    }
    //
  },
})